<?php
/**
 * 测试
 */
class CheckDiamondsHandler extends ScriptBase
{
	public function logic()
	{
		$rds = $this->redis('user_info');
		$mysql = $this->mysql('game');
		
		$uid = 0;
		$limit = 100;
		set_time_limit(100);
		while (true)
		{
			$sql = "SELECT `uid` FROM `d_user` WHERE `uid` > '{$uid}' ORDER BY `uid` ASC LIMIT {$limit}";
			// echo "{$sql}\n";
			if(!$mysql->query($sql)) break;
			if(count($rows = $mysql->fetch_all()) == 0) break;
			foreach ($rows as $row)
			{
				$uid = $row['uid'];
				$key = "U:{$uid}";
				if($rds->exists($key) 
				&& ($user = $rds->hmget($key, ['diamond', 'freeDiamond', 'paidDiamond']))
				&& $user['diamond'] != ($user['freeDiamond'] + $user['paidDiamond'])
				){
					echo "{$uid},{$user['diamond']},{$user['freeDiamond']},{$user['paidDiamond']}\r\n";
				}
			}
			usleep(0.01 * 1000000);
		}
	}
}